feat(hosts): add pi coding agent adapter - #675
Conversation
|
Thanks for adding a new host adapter. New-host reviews cover several independent seams — installation, scheduler lifecycle and real wake-up behavior, transcript preparation/shape, self-session exclusion, retrieval injection, and cross-platform cleanup — so this review will take longer than an ordinary feature review. I will validate these areas in order and report them incrementally rather than bundle everything into one pass. There will likely be multiple request-changes rounds as each seam is exercised end to end; that is expected for a host integration and is not a judgment on the overall direction of the contribution. I am starting with installation and scheduler creation/wake-up behavior first. |
xnne-bot
left a comment
There was a problem hiding this comment.
The install guide can complete and register \memU\memu-bridging-pi, but the registered Windows task cannot launch Pi, so the record bridge never starts.
schedule installresolved Pi to the npm shim...\pi.CMDand generated& '...\pi.CMD' -p $prompt.- Triggering the real S4U task reached the wrapper and read the prompt, then failed on that invocation with
NativeCommandError: 系统找不到指定的文件/LastTaskResult = 1. bridge.logstayed empty, no Pi session was created, and the manifest/jobs did not advance.schedule verifystill reported success because it only checks registration plus an auth probe in the current interactive shell; it does not exercise the S4U task.- In the same S4U task, replacing only the invocation with the shim's
node.exe <pi cli.js> -p $promptimmediately created a new Pi session and advanced the pending manifest/jobs. This isolates the failure to launching the npm.CMDshim under S4U, not Pi authentication or the prompt.
Please make the Windows scheduler invocation handle .cmd/.bat agent launchers correctly (and add coverage for that generated wrapper path), then verify by triggering the actual Task Scheduler entry and checking for a new Pi session plus advanced bridge traces. I am intentionally stopping this review pass at the installation/scheduler seam; the remaining host-adapter seams will be reviewed separately afterward.
|
I tested the Windows install through the real agent-facing path:
The installation completed, and both Content-free wrapper markers showed that Task Scheduler successfully started PowerShell and read & '...\pi.CMD' -p $prompt
On this machine, Pi is installed through npm. Interactive PowerShell resolves As an isolation test, I changed only the same S4U task invocation to the executable and JS entry point used by the shim: & '...\node.exe' '...\node_modules\@earendil-works\pi-coding-agent\dist\bundle\cli.js' -p $promptThat immediately created a new Pi session and advanced the pending manifest and jobs. This confirms that S4U, Pi authentication, the model, and the prompt all work; the blocker is launching the npm Please make the Windows scheduler handle Since your development machine is macOS, please also run the equivalent black-box test there: give a fresh Pi session only |
|
Addressed the installation/scheduler review in commit Windows npm launcher
|
|
Follow-up scope cleanup in |
xnne-bot
left a comment
There was a problem hiding this comment.
Two blocking inline changes: keep the Pi host contract at the CLI boundary, and keep its installer outside memU's guide.
|
Addressed the three blocking changes in
Validation: Windows scheduler tests I cannot rerun the requested real Windows S4U black-box from this macOS host, so I am not claiming that runtime evidence. The generated-wrapper regression covers the requested CLI-boundary behavior; the real Task Scheduler wake-up still needs confirmation on Windows via the Pi session, |
There was a problem hiding this comment.
The CLI-boundary changes now match the requested design. We will run the real Windows S4U task on our side; you only need to keep the PATH-resolvable pi invocation supported on Windows. Please continue to ensure the macOS path works normally, including a real OS-scheduled wake-up that produces a new Pi session and advances bridge.log, jobs, and manifest traces. One remaining cleanup is inline.
There was a problem hiding this comment.
Pi can now be launched by the Windows S4U task, but scheduled-session self-skip is broken in platform-independent transcript identity code and therefore affects Windows Task Scheduler as well as macOS/Linux cron or launchd. Windows is the concrete reproduction environment; the blocking mismatch is inline.
|
Addressed the Pi self-session identity mismatch in
Validation: focused host/self-session tests |
xnne-bot
left a comment
There was a problem hiding this comment.
The self-session identity fix is correct. One final blocking prepare-output privacy seam remains for Pi, inline.
Co-authored-by: Korewaxnne <2557248400@qq.com>
4a3a102 to
efc80cf
Compare
|
Addressed the Pi prepare-output privacy seam in
Validation: focused host/self-session/scheduler tests |
xnne-bot
left a comment
There was a problem hiding this comment.
Approved for the current revision. I will conduct a further manual review later; it may take some time. Thank you for your patience.
There was a problem hiding this comment.
请移除 Pi 的 headless-auth gate,并明确本 adapter 只处理默认 Pi session store。
-
从
src/memu/hosts/pi/cli.py删除:needs_headless_auth=True, auth_hint=...,
安装是由已运行的 Pi agent CLI 执行的;能到达此指南即表示该 Pi CLI 已有可工作的 provider 配置。Claude Code 的问题是 Desktop 登录与 standalone
claudeCLI 是两个身份边界,Pi 没有这个前提。memu-pi schedule install/verify不应再执行pi -p ping,或将/login、API key、persistent credential 作为 memU 的安装门。 -
memu-pi暂时只支持默认、固定的 Pi store:~/.pi/agent/sessions。删除sessions.py对PI_CODING_AGENT_DIR/PI_CODING_AGENT_SESSION_DIR的环境读取,删除 Pi spec 的schedule_prepare_session_dir=True,并删除 INSTALL/BRIDGING_TASK 中关于PI_CODING_AGENT_DIR、PI_CODING_AGENT_SESSION_DIR、settings.json.sessionDir、per-run--session-dir以及改写 scheduled prompt 的支持承诺。这是有意的拒绝,不是尚未补齐的 wrapper 功能。bridging 的 session source、cursor/manifest 和 host working tree 必须长期绑定同一个稳定 store;而这些 Pi override 可在安装后随时改为另一个目录、unset,或只存在于交互 shell,cron/S4U 的新进程无法可靠知道以后每次 Pi 使用哪一个。把安装时路径写死会在变更后静默读取旧 store;每次跟随环境会使同一个 cursor 在不同 store 间切换,造成漏读、重读或错误 self-skip。转运变量到 wrapper 或在 prompt 烘焙路径都只是隐藏这个不稳定契约。
因此,用户将 Pi 配置到非默认 agent/session directory 时,该目录的 sessions 不会进入 memU 的 memorize/bridging 流程;这比声称支持、却可能在未来的 scheduler run 中读错目录安全。未来若需要支持迁移,必须先设计显式、持久化、可验证的 source migration,而不是把每次运行可变的 Pi 配置当作 scheduled bridge 的数据源。
-
删除 INSTALL/BRIDGING_TASK 中 scheduler “runs a headless authentication probe”及“checks registration and authentication”的表述。验证应是注册 task 后触发真实 OS task,确认新 Pi session、
bridge.log和 jobs/manifest traces。
Pi's interactive CLI and scheduled pi -p share ~/.pi/agent/auth.json, so memU must not probe /login or an API key at schedule install/verify. That gate belongs to Claude Code, whose desktop login is invisible to standalone claude. Scheduled prepare stays on the default ~/.pi/agent/sessions layout; baking an install-time --session-dir would freeze a path the OS task cannot see.
|
Thank you for the careful review. Addressed the scheduler-auth and custom-session-dir review in This is not the Claude Code case. Claude Code needs
Validation: focused host/self-session/scheduler tests |
| from typing import ClassVar | ||
|
|
||
| from memu.hosts.base import RecordKind, TranscriptSource | ||
|
|
There was a problem hiding this comment.
[blocking] 请把这两个值收窄为固定默认常量:
AGENT_DIR = "~/.pi/agent"
SESSION_DIR = "~/.pi/agent/sessions"并移除 os import。
这不是遗漏 scheduler forwarding 的请求,而是有意拒绝 Pi 的可变 directory override。当前文档和 scheduler 已声明 scheduled bridge 只支持默认 layout,也已不再把安装时 session dir 烘焙到 prompt;但此处仍会读取 PI_CODING_AGENT_DIR / PI_CODING_AGENT_SESSION_DIR,且 cli.py 用 AGENT_DIR 构造 instruction/skills path。
若安装时的 Pi 进程设置了这些变量,手动 memu-pi prepare 会以非默认 store 产生 cursor/manifest,而之后 cron/S4U 的新环境通常回到默认 store;反过来,用户之后修改或 unset 变量也会令同一 ~/.memu/hosts/pi working tree 在不同 session source 间切换。写死安装时的路径、把变量转运到 wrapper、或把它们写进 prompt,都只会把同一不稳定契约延后暴露。
默认 ~/.pi/agent/sessions 是本 adapter 当前唯一稳定 source。用户将 Pi 配置到非默认 agent/session directory 时,那个 directory 的 sessions 应明确不进入 memU memorize/bridging,优于声称支持却可能在后续 scheduled run 静默读错 store。未来若要支持它,需要单独的显式、持久化、可验证 source migration;本 PR 不要实现该能力。
AGENT_DIR and SESSION_DIR no longer follow PI_CODING_AGENT_DIR or PI_CODING_AGENT_SESSION_DIR. Manual prepare and the later cron/S4U prepare must share ~/.pi/agent/sessions; reading process env would make the install-time cursor track a store the scheduled task does not inherit. Custom Pi directories stay out of this adapter; a later PR would need an explicit source migration.
|
@xnne-bot Thank you for the careful follow-up. Addressed the remaining directory-override leak in
Validation: focused host/self-session/scheduler tests |
📝 Pull Request Summary
Add a dedicated
memu-piadapter for pi coding agent's v3 JSONL sessions,global instructions, skills, and scheduled bridging.
Fixes #674.
✅ What does this PR do?
PiTranscriptSourcefor~/.pi/agent/sessions/<encoded-cwd>/*.jsonl;toolResult,bashExecution, and pure assistanttoolCallentries to thetool track;
memu-piCLI by reusing the existingHostSpecand bridgingpipeline;
PI_CODING_AGENT_DIRandPI_CODING_AGENT_SESSION_DIR;memu-agent detect ~/.pito the dedicated adapter;🤔 Why is this change needed?
The generic typed-tree classifier treats pure assistant
toolCallrows asconversation messages. A read-only sample of 10 recent real pi sessions found
385 such rows. The dedicated source classifies all 385 as tool records and can
also use pi's stable instruction, skill, session, and headless execution paths.
🔍 Type of Change
✅ PR Quality Checklist
Validation:
make checkmake test(604 passed, 8 skipped)TOOL📌 Optional